import { Node } from "cc";
import { ViewUtil } from "db://app-game/core/utils/ViewUtil";
import { ecs } from "db://app-game/libs/ecs/ECS";
import { SkillIconModelComp } from "./model/SkillIconModelComp";
import { SkillIconViewComp } from "./view/SkillIconViewComp";
/** 技能图标实例 */
@ecs.register("SkillIcon")
export class SkillIcon extends ecs.Entity {
  // 数据层
  SkillIconModel!: SkillIconModelComp;

  // 视图层
  SkillIconView!: SkillIconViewComp;
  init() {
    this.add(SkillIconModelComp);
  }

  /** 加载图标 */
  load(id: number, parent: Node) {
    this.SkillIconModel.id = id;
    const { prefabPath } = this.SkillIconModel.data;
    let node = ViewUtil.createPrefabNode(prefabPath);
    let mv = node.getComponent(SkillIconViewComp);
    this.add(mv);
    node.parent = parent;
  }
}
